<template>
  <div id="contain">
    <div>
      <el-table
        :data="tableList"
        style="width: 945px"
        stripe
        :row-style="rowStyle"
        :cell-style="cellStyle"
      >
        <el-table-column prop="title" label="标题" width="180" align="center">
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" align="center">
        </el-table-column>
        <el-table-column prop="status" label="状态" align="center">
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button size="mini" @click="chexiao(scope.row)"
              >撤销</el-button
            >
            <el-button size="mini" @click="chakan(scope.row)"
              >查看</el-button
            >
            </template
          >
        </el-table-column>
      </el-table>
    </div>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="page"
        :page-sizes="[10, 15, 20]"
        :page-size="limit"
        layout="sizes, prev, pager, next"
        :total="totalCount"
      >
      </el-pagination>
    </div>
    <el-dialog title="查看意见反馈信息" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="标题：" :label-width="formLabelWidth">
          <el-input v-model="form.title" disabled></el-input>
        </el-form-item>
        <el-form-item label="联系方式：" :label-width="formLabelWidth">
          <el-input v-model="form.contact" disabled></el-input>
        </el-form-item>
        <el-form-item label="意见内容：" :label-width="formLabelWidth">
          <el-input
            type="textarea"
            :rows="8"
            v-model="form.content"
            disabled
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogFormVisible = false"
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      token: window.localStorage.getItem("token"),
      tableList: [],
      page: 1,
      limit: 10,
      totalCount: 0,
      form: {},
      formLabelWidth: "120px",
      dialogFormVisible: false,
    };
  },
  mounted() {
    this.fn();
  },
  methods: {
    fn() {
      this.$axios({
        method: "post",
        url: "/feedback/list/current",
        headers: { token: this.token },
        data: {},
      }).then((res) => {
        this.tableList = res.data.page;
        this.totalCount = res.data.page.length;
        this.tableList.forEach((item) => {
          item.status = item.status === 1 ? "已处理" : "未处理";
        });
      });
    },
    rowStyle() {
      return { height: "60px" };
    },
    handleSizeChange(val) {
      this.limit = val;
      this.fn()
    },
    handleCurrentChange(val) {
      this.page = val;
      this.fn()
    },
     chakan(k) {
     this.form=k
      this.dialogFormVisible = true;
    },
    chexiao(k) {
      this.$axios({
        method: "post",
        url: "/feedback/del",
        headers: { token: this.token },
        data: { id: k.id },
      }).then((res) => {
        if (res.data.code === 0) {
          this.$message({
            type: "success",
            message: "撤销成功！",
          });
          this.fn();
        }
        if (res.data.code === 500) {
          this.$message({
            type: "error",
            message: res.data.msg,
          });
        }
      });
    },
    cellStyle(k) {
      if (k.columnIndex === 2) {
        if (k.row.status === "已处理") {
          return { color: "#33CC00" };
        } else {
          return { color: "blue" };
        }
      }
    },
  },
};
</script>
<style  scoped>
</style>>